<template>
	<view class="content">
		<view class="mokuai" style="margin: 20rpx;padding: 30rpx;">
			<view class="info_title" style="position: relative;">
			    用户资料
				<text class="info_more" style="width: 100rpx;" @tap="goeditor(id)" v-if="user.top!=3">编辑</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">用户姓名 </text>
				<text class="right">{{info.nickname}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">联系电话 </text>
				<text class="right" >{{info.phone}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">公司地址 </text>
				<text class="right" style="max-width: 70%;">{{info.address}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">紧急联系人 </text>
				<text class="right" >{{info.linkname}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">紧急联系人电话 </text>
				<text class="right" >{{info.linkphone}}</text>
			</view>
			<view class="clear shenhe-text shenhe-text1" >
				<text class="left">查看合同 </text>
			</view>
			<view class="clear hetong-list">
				<view class="left" v-for="(item,index) in hetong" :key="index">
					<image :src="item.url" @tap="yulan(item.url)"></image>
				</view>
				
			</view>
			<view class="clear shenhe-text shenhe-text1" >
				<text class="left">身份证/驾驶证 </text>
			</view>
			<view class="clear hetong-list">
				<view class="left" v-for="(item,index) in numberpic" :key="index">
					<image :src="item.url" @tap="yulan(item.url)"></image>
				</view>
			</view>
			<view class="clear shenhe-text shenhe-text1" >
				<text class="left">营业执照/工作证明 </text>
			</view>
			<view class="clear hetong-list">
				<view class="left" v-for="(item,index) in business" :key="index">
					<image :src="item.url" @tap="yulan(item.url)"></image>
				</view>
				
			</view>	
			<view class="clear shenhe-text shenhe-text1" >
				<text class="left">其他附件 </text>
			</view>
			<view class="clear hetong-list">
				<view class="left" v-for="(item,index) in otherpic" :key="index">
					<image :src="item.url" @tap="yulan(item.url)"></image>
				</view>
				
			</view>
		</view>
		<view class="mokuai" style="margin: 20rpx;padding: 30rpx;">
			<view class="info_title" style="position: relative;">
			    贷款情况
				<text class="info_more" @tap="daikuaninfo(info.id)" >查看更多</text>
				<text class="info_more" style="width: 150rpx;right: 175rpx;" @tap="goedu_kuang()" v-if="isshow_bianji">编辑额度</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">贷款总额（元） </text>
				<text class="right" >{{used_capital}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">个人额度（元） </text>
				<text class="right" >{{capital}}</text>
			</view>
			
			<view class="clear shenhe-text" >
				<text class="left">剩余额度（元） </text>
				<text class="right" >{{use_capital}}</text>
			</view>
			<view class="clear shenhe-text" >
				<text class="left">贷款项数（个） </text>
				<text class="right" >{{info.count}}</text>
			</view>		
		</view>
		<view class="menban" v-if="changemoney">
			<view class="gray"></view>
				<view class="menban-content" style="top:calc(50% - 200rpx);left: 10%;right: 10%;border-radius:5px ;">
					<view class="line_title blue_title" style="position: relative;">
						修改额度
						<image src="../../static/img/close-icon.png" class="close-icon" @tap="isalertAction"></image>
					</view>
					<view style="text-align: center;font-size: 14px;color: #666666;">当前金额：{{info.capital}}元</view>
					<view class="clear border_bottom" style="padding: 20px 30px;">
						<input type="number" style="font-size:14px;color: #666666;text-align: center;"  placeholder="请输入金额" v-model="money" placeholder-style="font-size:14px;color:#ccc;text-align: center;"/>
					</view>
					<button class="big_button" style="margin: 30rpx auto;" @tap="goedu()">
						确定修改
					</button>
				</view>
		</view>
	</view>
	
</template>

<script>
	import httpPath from '@/static/js/path.js';
	import {getlogin} from '@/static/js/login.js';
	import {fmoney} from '@/static/js/login.js';
	export default {
		data() {
			return {
			    user:"",//用户登录信息
				id:"",//用户id
				info:{},//用户详情
				capital:"",//个人额度
				used_capital:"",//贷款额度
				use_capital:"",//可用额度
				numberpic:[],
				business:[],
				otherpic:[],
				hetong:[],
				changemoney:false,
				isshow_bianji:false,
				money:"",
			}
		},
		onLoad(option) {
			this.user = getlogin();
			if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}	
			// this.id=id;
			this.id=option.id;
	        this.getinfo();
			if(this.user.top==3){
				this.isshow_bianji=true;	
			}
		},
		methods: {
			isalertAction(){
				this.changemoney=false;
			},
			goedu_kuang(){
				this.changemoney=true;
			},
			goedu(){
				if(!this.money){
					uni.showModal({
						showCancel:false,
						content:"请输入修改的额度"
					})
					return false;
				}
				console.log(this.money)
				uni.request({
					url: httpPath.filePath+'/api.php/index/user/member_capital/',
					method:'POST',
					header:{'content-type':'application/x-www-form-urlencoded'},
					data: {member_id:this.user.member_id,user_id:this.user.user_id,id:this.id,capital:this.money},
					success: (res) => {
						console.log(res)
						if(res.data.code=="200"){
							uni.showModal({
								showCancel:false,
								content:"修改额度成功",
								
							})
							this.changemoney=false;
							uni.navigateBack()
						}else{
							uni.showModal({
								showCancel:false,
								content:res.data.message,
								
							})
						}  
					}
				});
				
				
			},
			
			//将字符串转化成数组
			str_array(str){
				let arry=[];
			
				if(str.indexOf(",")==-1){
					arry.push(str)
				}else{
					arry=str.split(",")
				}
				return arry;
			},
	      //查看贷款情况
		   daikuaninfo(member_id){  
			  uni.navigateTo({
			  	url:"../myself/daikuanlist?member_id="+member_id
			  })
		   },getinfo(){
			   // console.log( {member_id:this.user.member_id,user_id:this.user.user_id,id:this.id})
			   uni.request({
			   	url: httpPath.filePath+'/api.php/index/user/look_customer',
			   	method:'POST',
			   	header:{'content-type':'application/x-www-form-urlencoded'},
			   	data: {member_id:this.user.member_id,user_id:this.user.user_id,id:this.id},
			   	success: (res) => {
					if(res.data.code=="200"){
						this.info=res.data.result;
						this.capital=fmoney(this.info.capital)
						this.used_capital=fmoney(this.info.used_capital)
						this.use_capital=fmoney(this.info.use_capital)
						// console.log(this.info)
						if(this.info.hetong!=null&&this.info.hetong!=""&&this.info.hetong!=0){
							// this.numberpic=res.data.result.numberpic+",";
							// console.log(this.numberpic)
							let num=this.str_array(this.info.hetong);
							for (let i=0;i<num.length;i++) {
								this.hetong.push({url:httpPath.filePath+"/static/upload/image/"+num[i]})
							}
							
						}
						if(this.info.numberpic!=null&&this.info.numberpic!=""&&this.info.numberpic!=0){
							// this.numberpic=res.data.result.numberpic+",";
							console.log(this.numberpic)
							let num=this.str_array(this.info.numberpic);
							for (let i=0;i<num.length;i++) {
								this.numberpic.push({url:httpPath.filePath+"/static/upload/image/"+num[i]})
							}
							
						}	
						if(this.info.business!=null&&this.info.business!=""&&this.info.business!=0){
							// this.business=res.data.result.business+",";
							let num=this.str_array(this.info.business);
							for (let i=0;i<num.length;i++) {
								this.business.push({url:httpPath.filePath+"/static/upload/image/"+num[i]})
							}
						}
						if(this.info.otherpic!=null&&this.info.otherpic!=""&&this.info.otherpic!=0){
							// this.otherpic=res.data.result.otherpic+",";
							let num=this.str_array(this.info.otherpic);
							for (let i=0;i<num.length;i++) {
								this.otherpic.push({url:httpPath.filePath+"/static/upload/image/"+num[i]})
							}
							
						}
						
					}
			   		   
			   	}
			   });
		   }
		   //点击跳转详情
		   ,goinfo(){
			   uni.navigateTo({
			   	url:"../myself/info"
			   })
		   }	// 预览图片
	      ,yulan(img){
				uni.previewImage({
					  urls: [img],
					  longPressActions: {
						  // itemList: ['发送给朋友', '保存图片', '收藏'],
						  success: function(data) {
							  console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						  },
						  fail: function(err) {
							  console.log(err.errMsg);
						  }
					  }
				});
			},
		     goeditor(id){
				 uni.navigateTo({
				 	url:"editkehu?id="+id
				 })
			 }
		}
	}
</script>

<style>
	@import "../../colorui/main.css";
	.shenhe-text1{height: 40px;line-height: 40px;color: #323232;}
	.info_title{padding-bottom: 8px;margin-bottom: 8px;}
</style>
